// pages/reconciliationDetails/reconciliationDetails.js
let app = getApp();
let util = require("../../utils/util");
import { getMonthTotalSumApi } from "../../api/index.js";
import { formatDate } from "../../utils/formatDate.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageAllHeight: app.globalData.pageAllHeight - 140,
    parkId: null,
    firstAndLastTime: util.getFirstAndLastDay(),
    monthTotalSum: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    if (options.parkId) {
      this.setData({
        parkId: options.parkId,
      });
      this.getMonthTotalSum();
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  changeDate(e) {
    this.setData({
      "firstAndLastTime.startTime": e.detail.startTimestamp,
      "firstAndLastTime.endTime": e.detail.endTimestamp,
    });
    this.getMonthTotalSum();
  },

  //查询停车总量列表
  async getMonthTotalSum() {
    try {
      const { startTime, endTime } = this.data.firstAndLastTime;
      const { parkId } = this.data;
      const { data: res } = await getMonthTotalSumApi({
        parkId,
        startTime,
        endTime,
			});
			let newDayList = res.data.dayList
			newDayList=newDayList.reverse()
      newDayList.forEach((item) => {
        // 年月日分割
        const year = item.nowDate.slice(0, 4);
        const month = item.nowDate.slice(4, 6);
        const day = item.nowDate.slice(6, 8);
        item.nowDate = `${year}-${month}-${day}`;
      });
      this.setData({
        monthTotalSum: res.data,
      });
    } catch (error) {
      console.error(error);
    }
  },
});
